home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DESQVIEW.SWG / 0006_DESQVIEW API Routines.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  16KB  |  575 lines

  1. {
  2. ********************************************************************
  3. *                                                                  *
  4. *  DESQview API routines                                           *
  5. *  for Turbo Pascal 6.0                                            *
  6. *  by Jonathan L. Zarate                                           *
  7. *  Released to the Public Domain                                   *
  8. *                                                                  *
  9. ********************************************************************
  10. }
  11. {
  12.   ** Please refer to Ralf Brown's Interrupt List
  13.   ** for additional information.
  14. }
  15.  
  16. Unit DV;
  17.  
  18. Interface
  19.  
  20. Type
  21.  Msg_Write2 = record
  22.                len : longint;
  23.                str : pointer;
  24.               end;
  25.  Msg_Write2_NewWin = record
  26.                       len    : longint;
  27.                       str    : pointer;
  28.                       handle : pointer;
  29.                      end;
  30.  
  31. const
  32. { Stream Types }
  33.  WinStream     = $00;
  34.  QueryStream   = $01;
  35.  ManagerStream = $10;
  36.  
  37. { Manager Streams }
  38.  MStream_MoveHoriz    = $00;     { horizontal movement  }
  39.  MStream_MoveVert     = $01;     { vertical movement  }
  40.  MStream_ChangeWidth  = $02;     { width change  }
  41.  MStream_ChangeHeight = $03;     { height change  }
  42.  MStream_ScrollHoriz  = $04;     { horizontal scroll  }
  43.  MStream_ScrollVert   = $05;     { vertical scroll  }
  44.  MStream_CloseWindow  = $06;     { close window option }
  45.  MStream_HideWindow   = $07;     { hide window option }
  46.  MStream_FreezeApp    = $08;     { freeze window option }
  47.  MStream_ScissorsMenu = $0E;     { scissors menu }
  48.  MStream_MainMenu     = $10;     { main DESQview menu }
  49.  MStream_SwitchWinMenu= $11;     { switch windows menu }
  50.  MStream_OpenWinMenu  = $12;     { open windows menu }
  51.  MStream_QuitMenu     = $13;     { quit menu }
  52.  
  53. { Window/Query streams }
  54.  WStream_CursorRow    = $A0;     { Cursor row }
  55.  WStream_CursorColumn = $A1;     { Cursor Column }
  56.  WStream_ScrollTopRow = $A2;     { Top row of scrolling region }
  57.  
  58. { DVError Constants }
  59.  DVErrorMouEither   = 00;        { use either mouse buttons to remove window }
  60.  DVErrorMouRight    = 32;        { use right mouse button to remove window }
  61.  DVErrorMouLeft     = 64;        { use left mouse button to remove window }
  62.  DVErrorBeep        = 128;       { beep on error }
  63. { ----------------------- }
  64.  
  65. const
  66.  InDV        : boolean = false;  { In DESQview flag }
  67.  DV_Version  : word = $0000;     { DESQview version }
  68.  
  69. var
  70.  DVArray     : array[1..80] of byte; { stream array }
  71.  
  72. function  DVInit : pointer;
  73. procedure DVGetVersion;
  74. function  DVGetShadowSeg( VideoSeg : word ) : word;
  75. procedure DVPause;
  76. procedure DVBeginC;
  77. procedure DVEndC;
  78. function  DVAPPNum : word;
  79. procedure DVSendMsg( Handle : pointer; _bh, _bl : byte; size : word; var param);
  80. procedure DVStream( Handle : pointer; mode : byte; params : string );
  81. function  DVGetHandle( HandleType : byte ) : pointer;
  82. procedure DVSound( Handle : pointer; frequency, duration : word );
  83. procedure DVError( Handle : pointer; xsize, ysize : byte; msg : string; params:byte);
  84. procedure DVAPILevel( major, minor : byte );
  85. procedure DVWrite( Handle : pointer; s : string );
  86. procedure DVWriteln( Handle : pointer; s : string );
  87. function  DVNewWin( x, y : word ) : pointer;
  88. procedure DVFree( var Handle : pointer );
  89. function  DVTimer_New : pointer;
  90. procedure DVTimer_Start( Handle : pointer; Time : longint );
  91. function  DVTimer_Len( Handle : pointer ) : longint;
  92. { ---- Window Streams ---- }
  93. procedure DVClear( Handle : pointer );
  94. procedure DVRedraw( Handle : pointer );
  95. procedure DVResize( Handle : pointer; x, y : byte );
  96. procedure DVMove( Handle : pointer; x, y : shortint );
  97. procedure DVTitle( Handle : pointer; title : string );
  98. procedure DVMove2( Handle : pointer; x, y : shortint );
  99. procedure DVResize2( Handle : pointer; x, y : shortint );
  100. procedure DVSetAttr( Handle : pointer; color : byte );
  101. procedure DVFrameAttr( Handle : pointer; color : byte );
  102. procedure DVFrameOn( Handle : pointer; b : boolean );
  103. procedure DVWinUnHide( Handle : pointer );
  104. procedure DVWinHide( Handle : pointer );
  105. procedure DVGotoXY( Handle : pointer; x, y : byte );
  106. procedure DVSetVirtualWinSize( Handle : pointer; x, y : byte );
  107. { -- Manager Streams -- }
  108. procedure DVAllow( Handle : pointer; command : byte );
  109. procedure DVDisallow( Handle : pointer; command : byte );
  110. procedure DVForeOnly( Handle : pointer; b : boolean );
  111. procedure DVMinWinSize( Handle : pointer; x, y : byte );
  112. procedure DVMaxWinSize( Handle : pointer; x, y : byte );
  113. procedure DVForceForeground( Handle : pointer );
  114. procedure DVForceBackground( Handle : pointer );
  115. procedure DVTopProcess( Handle : pointer );
  116. procedure DVBottomProcess( Handle : pointer );
  117. { ---- Query Streams ---- }
  118. procedure DVQSize( Handle : pointer; var x, y : byte );
  119. procedure DVQPos( Handle : pointer; var x, y : shortint );
  120. procedure DVQVirtualWinSize( Handle : pointer; var x, y : byte );
  121. function  DVWhereX( Handle : pointer ) : shortint;
  122. function  DVWhereY( Handle : pointer ) : shortint;
  123.  
  124. Implementation
  125.  
  126. function DVInit : pointer;
  127. begin
  128.  { get DESQview version & get our window handle }
  129.  DVGetVersion;
  130.  if InDV then DVInit:=DVGetHandle(1);
  131. end;
  132.  
  133. procedure DVGetVersion; assembler;
  134. asm
  135.  { get DESQview version/set InDV flag }
  136.  mov cx,'DE'
  137.  mov dx,'SQ'
  138.  mov ax,2b01h
  139.  int 21h
  140.  cmp al,0ffh
  141.  je @GV1
  142.  mov DV_Version,bx
  143.  mov InDV,True
  144.  jmp @GV2
  145. @GV1:
  146.  mov InDV,False
  147. @GV2:
  148. end;
  149.  
  150. function DVGetShadowSeg( VideoSeg : word ) : word; assembler;
  151. asm
  152.  { get task's shadow buffer & start shadowing }
  153.  mov ax,VideoSeg
  154.  mov es,ax
  155.  mov di,0
  156.  mov ah,0feh
  157.  int 10h
  158.  mov ax,es
  159.  { di=offset ??don't know if used?? }
  160. end;
  161.  
  162. procedure DVPause; assembler;
  163. asm
  164.  { give up CPU time }
  165.  mov ax,1000h
  166.  int $15
  167. end;
  168.  
  169. procedure DVBeginC; assembler;
  170. asm
  171.  { begin critical region }
  172.  mov ax,101bh
  173.  int $15
  174. end;
  175.  
  176. procedure DVEndC; assembler;
  177. asm
  178.  { end critical region }
  179.  mov ax,101ch
  180.  int $15
  181. end;
  182.  
  183. function DVAPPNum : word; assembler;
  184. asm
  185.  { get application's switch number }
  186.  mov ax,0de07h
  187.  int 15h
  188. end;
  189.  
  190. procedure DVSendMsg( Handle : pointer; _BH, _BL : byte;
  191.                       size : word; var param ); assembler;
  192. asm
  193.  std           { string goes backwards }
  194.  mov dx,sp     { save sp }
  195.  
  196.  mov cx,size   { load size of param }
  197.  jcxz @SM2     { if zero then don't push anything }
  198.  
  199.  mov bx,ds     { save ds }
  200.  
  201.  lds si,param  { load address of param }
  202.  add si,cx     { start from the top }
  203.  dec si        { minus 2 }
  204.  dec si        { ^^^^^^^ }
  205.  shr cx,1      { cx:=cx div 2 }
  206. @SM1:
  207.  lodsw         { load 1 word }
  208.  push ax       { push it }
  209.  loop @SM1      { if cx > 0 loop }
  210.  
  211.  mov ds,bx     { restore ds }
  212. @SM2:
  213.  les di,Handle { get handle }
  214.  mov ax,es     { move es to ax for compare }
  215.  cmp ax,0      { if segment is 0 then }
  216.  je @SM3       { don't push handle }
  217.  push es       { push segment }
  218.  push di       { push offset }
  219. @SM3:
  220.  mov ah,$12
  221.  mov bh,_bh
  222.  mov bl,_bl
  223.  int $15       { call dv }
  224.  
  225.  cld           { string goes forward }
  226.  mov ax,sp     { calculate the number of }
  227.  mov cx,dx     { returned parameter(s) }
  228.  sub cx,ax     { in stack }
  229.  
  230.  jcxz @SMX      { exit if none }
  231.  les di,param  { load address of param }
  232.  add di,size
  233.  shr cx,1      { cx:=cx div 2 }
  234. @SM4:
  235.  pop ax
  236.  stosw
  237.  loop @SM4
  238. @SMX:
  239. end;
  240.  
  241. function DVGetHandle( HandleType : byte ) : pointer; assembler;
  242. asm
  243.  { return object handle }
  244.  mov ah,$12
  245.  mov bh,$00
  246.  mov bl,HandleType
  247.  int $15
  248.  pop ax
  249.  pop dx
  250. end;
  251.  
  252. procedure DVSound( Handle : pointer; frequency, duration : word ); assembler;
  253. asm
  254.  { generate a sound }
  255.  mov ax,$1019
  256.  mov bx,frequency
  257.  mov cx,duration   { in 18.2 ticks/sec }
  258.  int $15
  259. end;
  260.  
  261. procedure DVError( handle : pointer; xsize, ysize : byte; msg : string; params: byte);
  262. assembler;
  263. asm
  264.  { pop-up an error box }
  265.  {
  266.    use DVERRORxxxxx for PARAMS
  267.    example: DVError(Handle1, 80, 25, 'Don't Touch That!',
  268.                     DVErrorMouEither+DVErrorBeep);
  269.  }
  270.  mov ch,xsize
  271.  mov cl,ysize;
  272.  mov bh,params
  273.  les dx,Handle
  274.  mov dx,es
  275.  les di,msg
  276.  mov bl,es:[di]
  277.  inc di
  278.  mov ax,$101F
  279.  int $15
  280. end;
  281.  
  282. procedure DVAPILevel( major, minor : byte ); assembler;
  283. asm
  284.  { define the minimum API revision level than the program requires }
  285.  mov bh,major
  286.  mov bl,minor
  287.  mov ax,0de0bh
  288.  int 15h
  289. end;
  290.  
  291. procedure DVStream( handle : pointer; mode : byte; params : string );
  292. var
  293.  Msg : Msg_Write2;
  294. begin
  295.  { send a stream of opcode(s) }
  296.  DVArray[1]:=$1B;
  297.  DVArray[2]:=mode; { stream mode }
  298.  DVArray[3]:=length(params);
  299.  DVArray[4]:=00;
  300.  move(params[1],DVArray[5],length(params));
  301.  with Msg do
  302.   begin
  303.    Str:=@DVArray;
  304.    Len:=Length(params)+4;
  305.   end;
  306.  DVSendMsg(Handle, $05, ord((handle=nil)), sizeof(Msg), Msg);
  307.  { Meaning of "ord((handle=nil))" }
  308.  { If handle=nil then return 1 else return 0 }
  309. end;
  310.  
  311. procedure DVWrite( Handle : pointer; s : string );
  312. var
  313.  Msg : Msg_Write2;
  314. begin
  315.  { write a string }
  316.  with Msg do
  317.   begin
  318.    str:=@s[1];
  319.    len:=length(s);
  320.   end;
  321.  DVSendMsg(Handle, $05, Ord((Handle=Nil)),  Sizeof(Msg), Msg );
  322. end;
  323.  
  324. procedure DVWriteln( Handle : pointer; s : string );
  325. begin
  326.  DVWrite(Handle, s+#13#10 );
  327. end;
  328.  
  329. function DVNewWin( x, y : word ) : pointer;
  330. var
  331.  Msg : Msg_Write2_NewWin;
  332. begin
  333.  { allocate new window ( X and Y are the window's size & virtual size }
  334.  DVArray[1]:=$1B;
  335.  DVArray[2]:=$00;
  336.  DVArray[3]:=$04;
  337.  DVArray[4]:=$00;
  338.  DVArray[5]:=$E6;
  339.  DVArray[6]:=y; { Y-Size }
  340.  DVArray[7]:=x; { X-Size }
  341.  With Msg do
  342.   begin
  343.    Len:=$07;
  344.    Str:=@DVArray;
  345.    Handle:=Nil;
  346.    DVSendMsg( Nil, $05, $01, Sizeof(Msg)-4, Msg);
  347.    DVNewWin:=Handle;
  348.   end;
  349. end;
  350.  
  351. procedure DVFree( var Handle : pointer );
  352. begin
  353.  { free a handle (close a window/free a timer/etc..) }
  354.  DVSendMsg(Handle, $02, $00, $00, Handle );
  355.  Handle:=Nil;
  356. end;
  357.  
  358. function DVTimer_New : pointer;
  359. var
  360.  Handle : pointer;
  361. begin
  362.  { allocate a new timer }
  363.  DVSendMsg( Nil, $01, $0B, $00, Handle );
  364.  DVTimer_New:=Handle;
  365. end;
  366.  
  367. procedure DVTimer_Start( Handle : pointer; Time : longint );
  368. begin
  369.  { start a timer countdown (TIME is in 1/100 of a second) }
  370.  DVSendMsg(Handle, $0a, $00, sizeof(Time), Time);
  371. end;
  372.  
  373. function DVTimer_Len( Handle : pointer ) : longint;
  374. var
  375.  Len : longint;
  376. begin
  377.  { get current timer value (in 1/100 of a second) }
  378.  DVSendMsg(Handle, $09, $00, $00, Len);
  379.  DVTimer_Len:=Len;
  380. end;
  381.  
  382. { ---- Window Streams ---- }
  383.  
  384. procedure DVClear( Handle : pointer );
  385. begin
  386.  { clear window }
  387.  DVStream(Handle, WinStream, chr($E3))
  388. end;
  389.  
  390. procedure DVRedraw( Handle : pointer );
  391. begin
  392.  { redraw window }
  393.  DVStream(Handle, WinStream, chr($E4))
  394. end;
  395.  
  396. procedure DVResize( Handle : pointer; x, y : byte );
  397. begin
  398.  { resize window }
  399.  DVStream(Handle, WinStream, chr($C3)+chr(y)+chr(x));
  400. end;
  401.  
  402. procedure DVMove( Handle : pointer; x, y : shortint );
  403. begin
  404.  { move the window }
  405.  DVStream(Handle, WinStream, chr($C2)+chr(y)+chr(x))
  406. end;
  407.  
  408. procedure DVTitle( Handle : pointer; title : string );
  409. begin
  410.  { change window title }
  411.  DVStream(Handle, WinStream, chr($EF)+title[0]+title)
  412. end;
  413.  
  414. procedure DVMove2( Handle : pointer; x, y : shortint );
  415. begin
  416.  { set window position relative to the current position  }
  417.  { use negative (-1) values to move up/left }
  418.  DVStream(Handle, WinStream, chr($CA)+chr(y)+chr(x));
  419. end;
  420.  
  421. procedure DVResize2( Handle : pointer; x, y : shortint );
  422. begin
  423.  { set window size relative to the current size  }
  424.  { use negative (-1) values to shrink window }
  425.  DVStream(handle, WinStream, chr($CB)+chr(y)+chr(x));
  426. end;
  427.  
  428. procedure DVSetAttr( Handle : pointer; color : byte );
  429. begin
  430.  { set the output color }
  431.  DVStream(Handle, WinStream, chr($E2)+chr(color));
  432. end;
  433.  
  434. procedure DVFrameAttr( Handle : pointer; color : byte );
  435. begin
  436.  { set the frame color }
  437.  DVStream(Handle, WinStream, chr($ED)+chr($FF)+chr($08)+
  438.           chr(color)+chr(color)+chr(color)+chr(color)+
  439.           chr(color)+chr(color)+chr(color)+chr(color));
  440. end;
  441.  
  442. procedure DVFrameOn( Handle : pointer; b : boolean );
  443. begin
  444. { must use DVRedraw to remove the frame }
  445.  if b then DVStream(Handle, WinStream, chr($D6))
  446.   else DVStream(Handle, WinStream, chr($D7))
  447. end;
  448.  
  449. procedure DVWinUnHide( Handle : pointer );
  450. begin
  451.  { unhide a window }
  452.  DVStream(Handle, WinStream, chr($D4));
  453. end;
  454.  
  455. procedure DVWinHide( Handle : pointer );
  456. begin
  457.  { hide a window }
  458.  DVStream(Handle, WinStream, chr($D5));
  459. end;
  460.  
  461. procedure DVGotoXY( Handle : pointer; x, y : byte );
  462. begin
  463.  { positions the cursor at X, Y }
  464.  DVStream(Handle, WinStream, chr($C0)+chr(y-1)+chr(x-1));
  465. end;
  466.  
  467. procedure DVSetVirtualWinSize( Handle : pointer; x, y : byte );
  468. begin
  469.  { set window's virtual size }
  470.  DVStream(Handle, WinStream, chr($AB)+chr(x));
  471.  DVStream(Handle, WinStream, chr($AA)+chr(y));
  472. end;
  473.  
  474. { ---- Query Streams ---- }
  475.  
  476. procedure DVQSize( Handle : pointer; var x, y : byte );
  477. begin
  478.  { get the window size }
  479.  DVStream(Handle, QueryStream, chr($C3));
  480.  { result is in DVArray[6..7] }
  481.  y:=DVArray[6];
  482.  x:=DVArray[7];
  483. end;
  484.  
  485. procedure DVQPos( Handle : pointer; var x, y : shortint );
  486. begin
  487.  { get the window position }
  488.  DVStream(Handle, QueryStream, chr($C2));
  489.  { result is in DVArray[6..7] }
  490.  y:=DVArray[6];
  491.  x:=DVArray[7];
  492. end;
  493.  
  494. procedure DVQVirtualWinSize( Handle : pointer; var x, y : byte );
  495. begin
  496.  { get virtual window size }
  497.  DVStream(Handle, QueryStream, chr($AA));
  498.  Y:=DVArray[6];
  499.  DVStream(Handle, QueryStream, chr($AB));
  500.  X:=DVArray[6];
  501. end;
  502.  
  503. function DVWhereX( Handle : pointer ) : shortint;
  504. begin
  505.  { return the cursor's X position }
  506.  DVStream( Handle, QueryStream, chr($A1) );
  507.  DVWhereX:=DVArray[6];
  508. end;
  509.  
  510. function DVWhereY( Handle : pointer ) : shortint;
  511. begin
  512.  { return the cursor's Y position }
  513.  DVStream( Handle, QueryStream, chr($A0) );
  514.  DVWhereY:=DVArray[6];
  515. end;
  516.  
  517. { --- Manager Stream Procedures --- }
  518.  
  519. procedure DVAllow( Handle : pointer; command : byte );
  520. begin
  521.  { disallow a command (see constants "MStream_xxxxxx") }
  522.  DVStream(Handle, ManagerStream, chr(command));
  523. end;
  524.  
  525. procedure DVDisallow( Handle : pointer; command : byte );
  526. begin
  527.  { disallow a command (see constants "MStream_xxxxxx") }
  528.  DVStream(Handle, ManagerStream, chr(command+$20));
  529. end;
  530.  
  531. procedure DVForeOnly( Handle : pointer; b : boolean );
  532. begin
  533.  { B=TRUE if application runs on foreground only }
  534.  if b then DVStream(Handle, ManagerStream, chr($86))
  535.   else DVStream(Handle, ManagerStream, chr($87));
  536. end;
  537.  
  538. procedure DVMinWinSize( Handle : pointer; x, y : byte );
  539. begin
  540.  { define window's minimum size }
  541.  DVStream(Handle, ManagerStream, chr($88)+chr(y)+chr(x));
  542. end;
  543.  
  544. procedure DVMaxWinSize( Handle : pointer; x, y : byte );
  545. begin
  546.  { define window's maximum size }
  547.  DVStream(Handle, ManagerStream, chr($89)+chr(y)+chr(x));
  548. end;
  549.  
  550. procedure DVForceForeground( Handle : pointer );
  551. begin
  552.  { force process to run into foreground }
  553.  DVStream(Handle, ManagerStream, chr($C1));
  554. end;
  555.  
  556. procedure DVForceBackground( Handle : pointer );
  557. begin
  558.  { force process to run into background }
  559.  DVStream(Handle, ManagerStream, chr($C9));
  560. end;
  561.  
  562. procedure DVTopProcess( Handle : pointer );
  563. begin
  564.  { make current window topmost in process }
  565.  DVStream( Handle, ManagerStream, chr($C2) );
  566. end;
  567.  
  568. procedure DVBottomProcess( Handle : pointer );
  569. begin
  570.  { make current window bottom-most in process }
  571.  DVStream( Handle, ManagerStream, chr($CA) );
  572. end;
  573.  
  574. end.
  575.